﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Paint
{
    //Shape
    abstract class Shape
    {
        public abstract void Draw(Graphics gr);
        public abstract Rectangle BoundedRec();
        protected Color borderColor = Color.Black;
        public Color BorderColor
        {
            get { return borderColor; }
            set { borderColor = value; }
        }
        protected bool selected = false;
        public bool Selected
        {
            get { return selected; }
            set { selected = value; }
        }
    }


    //Line
    class Line :Shape
    {
        private Point p1, p2;
        public Line(Point p1, Point p2)
        {
            this.p1 = p1;
            this.p2 = p2;
        }
        public Point StartPoint
        {
            get { return p1; }
            set { p1 = value; }
        }
        public Point EndPoint
        {
            get { return p2; }
            set { p2 = value; }
        }

        public override void Draw(Graphics gr)
        {            
            Pen p = new Pen (borderColor);
            if (selected)
                p = new Pen(Canvas.SelectedColor);
            gr.DrawLine(p, this.p1, this.p2);
        }

        public override Rectangle BoundedRec()
        {
            Point p = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
            Size s = new Size(Math.Abs(p1.X - p2.X), Math.Abs(p1.Y - p2.Y));
            return new Rectangle(p, s);
        }
    }

    //Rectangle
    class MyRectangle : Shape
    {
        private Point p1, p2;
        private int width, height;

        public MyRectangle(Point p1, Point p2, int width, int height)
        {
            this.p1 = p1;
            this.p2 = p2;
            this.width = width;
            this.height = height;
        }

        public Point StartPoint
        {
            get { return p1; }
            set { p1 = value; }
        }

        public Point EndPoint
        {
            get { return p2; }
            set { p2 = value; }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        public int Height
        {
            get { return height; }
            set { height = value; }
        }

        public override void Draw(Graphics gr)
        {            
            Pen MyPen = new Pen (borderColor);
            if (selected)
                MyPen = new Pen(Canvas.SelectedColor);
            Point p = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
            gr.DrawRectangle(MyPen, p.X, p.Y , width, height);
        }

        public override Rectangle BoundedRec()
        {
            Point p = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
            Size s = new Size(width, height);
            return new Rectangle(p, s);
        }
    }
        //Circle
    class Circle : Shape
    {
        private Point p1, p2;
        private int width, height;

        public Circle(Point p1, Point p2, int width, int height)
        {
            this.p1 = p1;
            this.p2 = p2;
            this.width = width;
            this.height = height;
        }

        public Point StartPoint
        {
            get { return p1; }
            set { p1 = value; }
        }

        public Point EndPoint
        {
            get { return p2; }
            set { p2 = value; }
        }

        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        public int Height
        {
            get { return height; }
            set { height = value; }
        }

        public override void Draw(Graphics gr)
        {
            Pen MyPen = new Pen(borderColor);
            if (selected)
                MyPen = new Pen(Canvas.SelectedColor);
            Point p = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
            gr.DrawEllipse(MyPen, p.X, p.Y, width, height);
        }

        public override Rectangle BoundedRec()
        {
            Point p = new Point(Math.Min(p1.X, p2.X), Math.Min(p1.Y, p2.Y));
            Size s = new Size(width, height);
            return new Rectangle(p, s);
        }

    }
}